<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>java 开发常用的 linux 命令 | 清峰小栈</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  <meta name="keywords" content="java" />
  
  
  
  
  <meta name="description" content="Java 开发常用的 Linux 命令知识积累 基本操作  Linux关机,重启  查看系统,CPU信息  建立软连接  rpm相关  sshkey  命令重命名  同步服务器时间  后台运行命令  强制活动用户退出  查看命令路径  查看进程所有打开最大fd数  配置dns  nslookup,查看域名路由表  last, 最近登录信息列表  设置固定ip  查看进程内加载的环境变量  查看进程">
<meta property="og:type" content="article">
<meta property="og:title" content="Java 开发常用的 Linux 命令">
<meta property="og:url" content="http://example.com/2021/11/30/Linux/Java%20%E5%BC%80%E5%8F%91%E5%B8%B8%E7%94%A8%E7%9A%84%20Linux%20%E5%91%BD%E4%BB%A4/index.html">
<meta property="og:site_name" content="清峰小栈">
<meta property="og:description" content="Java 开发常用的 Linux 命令知识积累 基本操作  Linux关机,重启  查看系统,CPU信息  建立软连接  rpm相关  sshkey  命令重命名  同步服务器时间  后台运行命令  强制活动用户退出  查看命令路径  查看进程所有打开最大fd数  配置dns  nslookup,查看域名路由表  last, 最近登录信息列表  设置固定ip  查看进程内加载的环境变量  查看进程">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2021-11-30T01:37:25.807Z">
<meta property="article:modified_time" content="2023-05-03T13:58:33.868Z">
<meta property="article:author" content="清峰">
<meta property="article:tag" content="java">
<meta name="twitter:card" content="summary">
  

  

  <link rel="icon" href="/qingfeng-blog/css/images/mylogo-2.png">
  <link rel="apple-touch-icon" href="/qingfeng-blog/css/images/mylogo-2.png">
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans|Montserrat:700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic" rel="stylesheet" type="text/css">
  <!-- <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"> -->
  <link href="/qingfeng-blog/css/font-awesome.css" rel="stylesheet">
  <style type="text/css">
    @font-face{font-family:futura-pt; src:url("/qingfeng-blog/css/fonts/FuturaPTBold.otf") format("woff");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt-light; src:url("/qingfeng-blog/css/fonts/FuturaPTBook.otf") format("woff");font-weight:lighter;font-style:normal;}
    @font-face{font-family:futura-pt-italic; src:url("/qingfeng-blog/css/fonts/FuturaPTBookOblique.otf") format("woff");font-weight:400;font-style:italic;}
}

  </style>
  
<link rel="stylesheet" href="/qingfeng-blog/css/style.css">


  
<script src="/qingfeng-blog/js/jquery-3.1.1.min.js"></script>

  
<script src="/qingfeng-blog/js/bootstrap.js"></script>


  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="/qingfeng-blog/css/bootstrap.css" >

  
    
<link rel="stylesheet" href="/qingfeng-blog/css/dialog.css">

  

  

  
    <link rel="stylesheet" href="/qingfeng-blog/css/header-post.css" >
  

  
  
  
    <link rel="stylesheet" href="/qingfeng-blog/css/vdonate.css" >
  

<meta name="generator" content="Hexo 6.3.0"></head>



  <body data-spy="scroll" data-target="#toc" data-offset="50">


  
  <div id="container">
    <div id="wrap">
      
        <header>

    <div id="allheader" class="navbar navbar-default navbar-static-top" role="navigation">
        <div class="navbar-inner">
          
          <div class="container"> 
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>

            
              <a class="brand" style="
                 border-width: 0px;  margin-top: 0px;"  
                href="#" data-toggle="modal" data-target="#myModal" >
                  <img width="155px" height="90px" alt="Hike News" src="/qingfeng-blog/css/images/mylogo-2.png">
              </a>
            
            
            <div class="navbar-collapse collapse">
              <ul class="hnav navbar-nav">
                
                  <li> <a class="main-nav-link" href="/qingfeng-blog/">首页</a> </li>
                
                  <li> <a class="main-nav-link" href="/qingfeng-blog/categories">分类</a> </li>
                
                  <li> <a class="main-nav-link" href="/qingfeng-blog/tags">标签</a> </li>
                
                  <li><div id="search-form-wrap">

    <form class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="" />
        <button type="submit" class="search-form-submit"></button>
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="Type something..." />
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: 'Posts',
            PAGES: 'Pages',
            CATEGORIES: 'Categories',
            TAGS: 'Tags',
            UNTITLED: '(Untitled)',
        },
        ROOT_URL: '/qingfeng-blog/',
        CONTENT_URL: '/qingfeng-blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/qingfeng-blog/js/insight.js"></script>


</div></li>
            </div>
          </div>
                
      </div>
    </div>

</header>



      
            
      <div id="content" class="outer">
        
          <section id="main" style="float:none;"><article id="post-Linux/Java 开发常用的 Linux 命令" style="width: 75%; float:left;" class="article article-type-post" itemscope itemprop="blogPost" >
<div id="container">
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" class="article-title" itemprop="name">
      Java 开发常用的 Linux 命令
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/qingfeng-blog/2021/11/30/Linux/Java%20%E5%BC%80%E5%8F%91%E5%B8%B8%E7%94%A8%E7%9A%84%20Linux%20%E5%91%BD%E4%BB%A4/" class="article-date">
	  <time datetime="2021-11-30T01:37:25.807Z" itemprop="datePublished">2021-11-30</time>
	</a>

      
    <a class="article-category-link" href="/qingfeng-blog/categories/Linux/">Linux</a>

      
	<a class="article-views">
	<span id="busuanzi_container_page_pv">
		PV:<span id="busuanzi_value_page_pv"></span>
	</span>
	</a>

      

    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="Java-开发常用的-Linux-命令知识积累"><a href="#Java-开发常用的-Linux-命令知识积累" class="headerlink" title="Java 开发常用的 Linux 命令知识积累"></a>Java 开发常用的 Linux 命令知识积累</h1><ul>
<li><p>基本操作</p>
</li>
<li><p>Linux关机,重启</p>
</li>
<li><p>查看系统,CPU信息</p>
</li>
<li><p>建立软连接</p>
</li>
<li><p>rpm相关</p>
</li>
<li><p>sshkey</p>
</li>
<li><p>命令重命名</p>
</li>
<li><p>同步服务器时间</p>
</li>
<li><p>后台运行命令</p>
</li>
<li><p>强制活动用户退出</p>
</li>
<li><p>查看命令路径</p>
</li>
<li><p>查看进程所有打开最大fd数</p>
</li>
<li><p>配置dns</p>
</li>
<li><p>nslookup,查看域名路由表</p>
</li>
<li><p>last, 最近登录信息列表</p>
</li>
<li><p>设置固定ip</p>
</li>
<li><p>查看进程内加载的环境变量</p>
</li>
<li><p>查看进程树找到服务器进程</p>
</li>
<li><p>查看进程启动路径</p>
</li>
<li><p>添加用户, 配置sudo权限</p>
</li>
<li><p>强制关闭进程名包含xxx的所有进程</p>
</li>
<li><p>vim操作</p>
</li>
<li><p>打开只读文件,修改后需要保存时(不用切换用户即可保存的方式)</p>
</li>
<li><p>查看磁盘, 文件目录基本信息</p>
</li>
<li><p>wc命令</p>
</li>
<li><p>常用压缩, 解压缩命令</p>
</li>
<li><ul>
<li>压缩命令</li>
<li>解压缩命令</li>
</ul>
</li>
<li><p>变更文件所属用户, 用户组</p>
</li>
<li><p>cp, scp, mkdir</p>
</li>
<li><p>比较两个文件</p>
</li>
<li><p>日志输出的字节数,可以用作性能测试</p>
</li>
<li><p>查看, 去除特殊字符</p>
</li>
<li><p>处理因系统原因引起的文件中特殊字符的问题</p>
</li>
<li><p>tee, 重定向的同时输出到屏幕</p>
</li>
<li><p>grep</p>
</li>
<li><p>awk</p>
</li>
<li><p>find检索命令</p>
</li>
<li><p>查看什么进程使用了该端口</p>
</li>
<li><p>获取本机ip地址</p>
</li>
<li><p>iptables</p>
</li>
<li><p>nc命令, tcp调试利器</p>
</li>
<li><p>tcpdump</p>
</li>
<li><p>跟踪网络路由路径</p>
</li>
<li><p>ss</p>
</li>
<li><p>netstat</p>
</li>
<li><p>top</p>
</li>
<li><p>dmesg,查看系统日志</p>
</li>
<li><p>iostat,磁盘IO情况监控</p>
</li>
<li><p>free,内存使用情况</p>
</li>
<li><p>sar,查看网络吞吐状态</p>
</li>
<li><p>vmstat, 给定时间监控CPU使用率, 内存使用, 虚拟内存交互, IO读写</p>
</li>
</ul>
<h2 id="基本操作"><a href="#基本操作" class="headerlink" title="基本操作"></a>基本操作</h2><h2 id="Linux关机-重启"><a href="#Linux关机-重启" class="headerlink" title="Linux关机,重启"></a>Linux关机,重启</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># 关机</span><br><span class="line">shutdown -h now</span><br><span class="line"></span><br><span class="line"># 重启</span><br><span class="line">shutdown -r now</span><br></pre></td></tr></table></figure>

<h2 id="查看系统-CPU信息"><a href="#查看系统-CPU信息" class="headerlink" title="查看系统,CPU信息"></a>查看系统,CPU信息</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"># 查看系统内核信息</span><br><span class="line">uname -a</span><br><span class="line"></span><br><span class="line"># 查看系统内核版本</span><br><span class="line">cat /proc/version</span><br><span class="line"></span><br><span class="line"># 查看当前用户环境变量</span><br><span class="line">env</span><br><span class="line"></span><br><span class="line">cat /proc/cpuinfo</span><br><span class="line"></span><br><span class="line"># 查看有几个逻辑cpu, 包括cpu型号</span><br><span class="line">cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c</span><br><span class="line"></span><br><span class="line"># 查看有几颗cpu,每颗分别是几核</span><br><span class="line">cat /proc/cpuinfo | grep physical | uniq -c</span><br><span class="line"></span><br><span class="line"># 查看当前CPU运行在32bit还是64bit模式下, 如果是运行在32bit下也不代表CPU不支持64bit</span><br><span class="line">getconf LONG_BIT</span><br><span class="line"></span><br><span class="line"># 结果大于0, 说明支持64bit计算. lm指long mode, 支持lm则是64bit</span><br><span class="line">cat /proc/cpuinfo | grep flags | grep &#x27; lm &#x27; | wc -l</span><br></pre></td></tr></table></figure>

<h2 id="建立软连接"><a href="#建立软连接" class="headerlink" title="建立软连接"></a>建立软连接</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ln -s /usr/local/jdk1.8/ jdk</span><br></pre></td></tr></table></figure>

<h2 id="rpm相关"><a href="#rpm相关" class="headerlink" title="rpm相关"></a>rpm相关</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 查看是否通过rpm安装了该软件</span><br><span class="line">rpm -qa | grep 软件名</span><br></pre></td></tr></table></figure>

<h2 id="sshkey"><a href="#sshkey" class="headerlink" title="sshkey"></a>sshkey</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"># 创建sshkey</span><br><span class="line">ssh-keygen -t rsa -C your_email@example.com</span><br><span class="line"></span><br><span class="line">#id_rsa.pub 的内容拷贝到要控制的服务器的 home/username/.ssh/authorized_keys 中,如果没有则新建(.ssh权限为700, authorized_keys权限为600)</span><br></pre></td></tr></table></figure>

<h2 id="命令重命名"><a href="#命令重命名" class="headerlink" title="命令重命名"></a>命令重命名</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 在各个用户的.bash_profile中添加重命名配置</span><br><span class="line">alias ll=&#x27;ls -alF&#x27;</span><br></pre></td></tr></table></figure>

<h2 id="同步服务器时间"><a href="#同步服务器时间" class="headerlink" title="同步服务器时间"></a>同步服务器时间</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo ntpdate -u ntp.api.bz</span><br></pre></td></tr></table></figure>

<h2 id="后台运行命令"><a href="#后台运行命令" class="headerlink" title="后台运行命令"></a>后台运行命令</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"># 后台运行,并且有nohup.out输出</span><br><span class="line">nohup xxx &amp;</span><br><span class="line"></span><br><span class="line"># 后台运行, 不输出任何日志</span><br><span class="line">nohup xxx &gt; /dev/null &amp;</span><br><span class="line"></span><br><span class="line"># 后台运行, 并将错误信息做标准输出到日志中 </span><br><span class="line">nohup xxx &gt;out.log 2&gt;&amp;1 &amp;</span><br></pre></td></tr></table></figure>

<h2 id="强制活动用户退出"><a href="#强制活动用户退出" class="headerlink" title="强制活动用户退出"></a>强制活动用户退出</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 命令来完成强制活动用户退出.其中TTY表示终端名称</span><br><span class="line">pkill -kill -t [TTY]</span><br></pre></td></tr></table></figure>

<h2 id="查看命令路径"><a href="#查看命令路径" class="headerlink" title="查看命令路径"></a>查看命令路径</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">which &lt;命令&gt;</span><br></pre></td></tr></table></figure>

<h2 id="查看进程所有打开最大fd数"><a href="#查看进程所有打开最大fd数" class="headerlink" title="查看进程所有打开最大fd数"></a>查看进程所有打开最大fd数</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ulimit -n</span><br></pre></td></tr></table></figure>

<h2 id="配置dns"><a href="#配置dns" class="headerlink" title="配置dns"></a>配置dns</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/resolv.conf</span><br></pre></td></tr></table></figure>

<h2 id="nslookup-查看域名路由表"><a href="#nslookup-查看域名路由表" class="headerlink" title="nslookup,查看域名路由表"></a>nslookup,查看域名路由表</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nslookup google.com</span><br></pre></td></tr></table></figure>

<h2 id="last-最近登录信息列表"><a href="#last-最近登录信息列表" class="headerlink" title="last, 最近登录信息列表"></a>last, 最近登录信息列表</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 最近登录的5个账号</span><br><span class="line">last -n 5</span><br></pre></td></tr></table></figure>

<h2 id="设置固定ip"><a href="#设置固定ip" class="headerlink" title="设置固定ip"></a>设置固定ip</h2><p>搜索公纵号：<a target="_blank" rel="noopener" href="https://mp.weixin.qq.com/s?__biz=MzI4OTA3NDQ0Nw==&mid=2455548310&idx=2&sn=28559512311234ab380c18f124ac5246&scene=21#wechat_redirect">MarkerHub</a>，关注回复[ <strong>vue</strong> ]获取前后端入门教程！</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ifconfig em1  192.168.5.177 netmask 255.255.255.0</span><br></pre></td></tr></table></figure>

<h2 id="查看进程内加载的环境变量"><a href="#查看进程内加载的环境变量" class="headerlink" title="查看进程内加载的环境变量"></a>查看进程内加载的环境变量</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 也可以去 cd /proc 目录下, 查看进程内存中加载的东西</span><br><span class="line">ps eww -p  XXXXX(进程号)</span><br></pre></td></tr></table></figure>

<h2 id="查看进程树找到服务器进程"><a href="#查看进程树找到服务器进程" class="headerlink" title="查看进程树找到服务器进程"></a>查看进程树找到服务器进程</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps auwxf</span><br></pre></td></tr></table></figure>

<h2 id="查看进程启动路径"><a href="#查看进程启动路径" class="headerlink" title="查看进程启动路径"></a>查看进程启动路径</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd /proc/xxx(进程号)</span><br><span class="line">ls -all</span><br><span class="line"># cwd对应的是启动路径</span><br></pre></td></tr></table></figure>

<h2 id="添加用户-配置sudo权限"><a href="#添加用户-配置sudo权限" class="headerlink" title="添加用户, 配置sudo权限"></a>添加用户, 配置sudo权限</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"># 新增用户</span><br><span class="line">useradd 用户名</span><br><span class="line">passwd 用户名</span><br><span class="line"></span><br><span class="line">#增加sudo权限</span><br><span class="line">vim /etc/sudoers</span><br><span class="line"># 修改文件里面的</span><br><span class="line"># root    ALL=(ALL)       ALL</span><br><span class="line"># 用户名 ALL=(ALL)       ALL</span><br></pre></td></tr></table></figure>

<h2 id="强制关闭进程名包含xxx的所有进程"><a href="#强制关闭进程名包含xxx的所有进程" class="headerlink" title="强制关闭进程名包含xxx的所有进程"></a>强制关闭进程名包含xxx的所有进程</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps aux|grep xxx | grep -v grep | awk &#x27;&#123;print $2&#125;&#x27; | xargs kill -9</span><br></pre></td></tr></table></figure>

<hr>
<h1 id="磁盘-文件-目录相关操作"><a href="#磁盘-文件-目录相关操作" class="headerlink" title="磁盘,文件,目录相关操作"></a>磁盘,文件,目录相关操作</h1><h2 id="vim操作"><a href="#vim操作" class="headerlink" title="vim操作"></a>vim操作</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">#normal模式下 g表示全局, x表示查找的内容, y表示替换后的内容</span><br><span class="line">:%s/x/y/g</span><br><span class="line"> </span><br><span class="line">#normal模式下</span><br><span class="line">0  # 光标移到行首(数字0)</span><br><span class="line">$  # 光标移至行尾</span><br><span class="line">shift + g # 跳到文件最后</span><br><span class="line">gg # 跳到文件头</span><br><span class="line"> </span><br><span class="line"># 显示行号</span><br><span class="line">:set nu</span><br><span class="line"> </span><br><span class="line"># 去除行号</span><br><span class="line">:set nonu</span><br><span class="line"> </span><br><span class="line"># 检索</span><br><span class="line">/xxx(检索内容)  # 从头检索, 按n查找下一个</span><br><span class="line">?xxx(检索内容)  # 从尾部检索</span><br></pre></td></tr></table></figure>

<h2 id="打开只读文件-修改后需要保存时-不用切换用户即可保存的方式"><a href="#打开只读文件-修改后需要保存时-不用切换用户即可保存的方式" class="headerlink" title="打开只读文件,修改后需要保存时(不用切换用户即可保存的方式)"></a>打开只读文件,修改后需要保存时(不用切换用户即可保存的方式)</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 在normal模式下</span><br><span class="line">:w !sudo tee %</span><br></pre></td></tr></table></figure>

<h2 id="查看磁盘-文件目录基本信息"><a href="#查看磁盘-文件目录基本信息" class="headerlink" title="查看磁盘, 文件目录基本信息"></a>查看磁盘, 文件目录基本信息</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"># 查看磁盘挂载情况</span><br><span class="line">mount</span><br><span class="line"></span><br><span class="line"># 查看磁盘分区信息</span><br><span class="line">df</span><br><span class="line"></span><br><span class="line"># 查看目录及子目录大小</span><br><span class="line">du -H -h</span><br><span class="line"></span><br><span class="line"># 查看当前目录下各个文件, 文件夹占了多少空间, 不会递归</span><br><span class="line">du -sh *</span><br></pre></td></tr></table></figure>

<h2 id="wc命令"><a href="#wc命令" class="headerlink" title="wc命令"></a>wc命令</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"># 查看文件里有多少行</span><br><span class="line">wc -l filename</span><br><span class="line"> </span><br><span class="line"># 看文件里有多少个word</span><br><span class="line">wc -w filename</span><br><span class="line"></span><br><span class="line"># 文件里最长的那一行是多少个字</span><br><span class="line">wc -L filename</span><br><span class="line"></span><br><span class="line"># 统计字节数</span><br><span class="line">wc -c</span><br></pre></td></tr></table></figure>

<h2 id="常用压缩-解压缩命令"><a href="#常用压缩-解压缩命令" class="headerlink" title="常用压缩, 解压缩命令"></a>常用压缩, 解压缩命令</h2><h3 id="压缩命令"><a href="#压缩命令" class="headerlink" title="压缩命令"></a>压缩命令</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">tar czvf xxx.tar 压缩目录</span><br><span class="line"> </span><br><span class="line">zip -r xxx.zip 压缩目录</span><br></pre></td></tr></table></figure>

<h3 id="解压缩命令"><a href="#解压缩命令" class="headerlink" title="解压缩命令"></a>解压缩命令</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">tar zxvf xxx.tar</span><br><span class="line"> </span><br><span class="line"># 解压到指定文件夹</span><br><span class="line">tar zxvf xxx.tar -C /xxx/yyy/</span><br><span class="line"> </span><br><span class="line">unzip xxx.zip</span><br></pre></td></tr></table></figure>

<h2 id="变更文件所属用户-用户组"><a href="#变更文件所属用户-用户组" class="headerlink" title="变更文件所属用户, 用户组"></a>变更文件所属用户, 用户组</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chown eagleye.eagleye xxx.log</span><br></pre></td></tr></table></figure>

<h2 id="cp-scp-mkdir"><a href="#cp-scp-mkdir" class="headerlink" title="cp, scp, mkdir"></a>cp, scp, mkdir</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">#复制</span><br><span class="line">cp xxx.log</span><br><span class="line"></span><br><span class="line"># 复制并强制覆盖同名文件</span><br><span class="line">cp -f xxx.log</span><br><span class="line"></span><br><span class="line"># 复制文件夹</span><br><span class="line">cp -r xxx(源文件夹) yyy(目标文件夹)</span><br><span class="line"></span><br><span class="line"># 远程复制</span><br><span class="line">scp -P ssh端口 username@10.10.10.101:/home/username/xxx /home/xxx</span><br><span class="line"></span><br><span class="line"># 级联创建目录</span><br><span class="line">mkdir -p /xxx/yyy/zzz</span><br><span class="line"></span><br><span class="line"># 批量创建文件夹, 会在test,main下都创建java, resources文件夹</span><br><span class="line">mkdir -p src/&#123;test,main&#125;/&#123;java,resources&#125;</span><br></pre></td></tr></table></figure>

<h2 id="比较两个文件"><a href="#比较两个文件" class="headerlink" title="比较两个文件"></a>比较两个文件</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">diff -u 1.txt 2.txt</span><br></pre></td></tr></table></figure>

<h2 id="日志输出的字节数-可以用作性能测试"><a href="#日志输出的字节数-可以用作性能测试" class="headerlink" title="日志输出的字节数,可以用作性能测试"></a>日志输出的字节数,可以用作性能测试</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 如果做性能测试, 可以每执行一次, 往日志里面输出 “.” , 这样日志中的字节数就是实际的性能测试运行的次数, 还可以看见实时速率.</span><br><span class="line">tail -f xxx.log | pv -bt</span><br></pre></td></tr></table></figure>

<h2 id="查看-去除特殊字符"><a href="#查看-去除特殊字符" class="headerlink" title="查看, 去除特殊字符"></a>查看, 去除特殊字符</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># 查看特殊字符</span><br><span class="line">cat -v xxx.sh</span><br><span class="line"></span><br><span class="line"># 去除特殊字符</span><br><span class="line">sed -i &#x27;s/^M//g’ env.sh  去除文件的特殊字符, 比如^M:  需要这样输入: ctrl+v+enter</span><br></pre></td></tr></table></figure>

<h2 id="处理因系统原因引起的文件中特殊字符的问题"><a href="#处理因系统原因引起的文件中特殊字符的问题" class="headerlink" title="处理因系统原因引起的文件中特殊字符的问题"></a>处理因系统原因引起的文件中特殊字符的问题</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"># 可以转换为该系统下的文件格式</span><br><span class="line">cat file.sh &gt; file.sh_bak</span><br><span class="line"></span><br><span class="line"># 先将file.sh中文件内容复制下来然后运行, 然后粘贴内容, 最后ctrl + d 保存退出</span><br><span class="line">cat &gt; file1.sh</span><br><span class="line"></span><br><span class="line"># 在vim中通过如下设置文件编码和文件格式</span><br><span class="line">:set fileencodings=utf-8 ，然后 w （存盘）一下即可转化为 utf8 格式，</span><br><span class="line">:set fileformat=unix</span><br><span class="line"></span><br><span class="line"># 在mac下使用dos2unix进行文件格式化</span><br><span class="line">find . -name &quot;*.sh&quot; | xargs dos2unix</span><br></pre></td></tr></table></figure>

<h2 id="tee-重定向的同时输出到屏幕"><a href="#tee-重定向的同时输出到屏幕" class="headerlink" title="tee, 重定向的同时输出到屏幕"></a>tee, 重定向的同时输出到屏幕</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">awk ‘&#123;print $0&#125;’ xxx.log | tee test.log</span><br></pre></td></tr></table></figure>

<hr>
<h1 id="检索相关"><a href="#检索相关" class="headerlink" title="检索相关"></a>检索相关</h1><h2 id="grep"><a href="#grep" class="headerlink" title="grep"></a>grep</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"># 反向匹配, 查找不包含xxx的内容</span><br><span class="line">grep -v xxx</span><br><span class="line"></span><br><span class="line"># 排除所有空行</span><br><span class="line">grep -v &#x27;^$&#x27;</span><br><span class="line"></span><br><span class="line"># 返回结果 2,则说明第二行是空行</span><br><span class="line">grep -n “^$” 111.txt    </span><br><span class="line"></span><br><span class="line"># 查询以abc开头的行</span><br><span class="line">grep -n “^abc” 111.txt </span><br><span class="line"></span><br><span class="line"># 同时列出该词语出现在文章的第几行</span><br><span class="line">grep &#x27;xxx&#x27; -n xxx.log</span><br><span class="line"></span><br><span class="line"># 计算一下该字串出现的次数</span><br><span class="line">grep &#x27;xxx&#x27; -c xxx.log</span><br><span class="line"></span><br><span class="line"># 比对的时候，不计较大小写的不同</span><br><span class="line">grep &#x27;xxx&#x27; -i xxx.log</span><br></pre></td></tr></table></figure>

<h2 id="awk"><a href="#awk" class="headerlink" title="awk"></a>awk</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># 以&#x27;:&#x27; 为分隔符,如果第五域有user则输出该行</span><br><span class="line">awk -F &#x27;:&#x27; &#x27;&#123;if ($5 ~ /user/) print $0&#125;&#x27; /etc/passwd </span><br><span class="line"></span><br><span class="line"># 统计单个文件中某个字符（串）(中文无效)出现的次数</span><br><span class="line">awk -v RS=&#x27;character&#x27; &#x27;END &#123;print --NR&#125;&#x27; xxx.txt</span><br></pre></td></tr></table></figure>

<h2 id="find检索命令"><a href="#find检索命令" class="headerlink" title="find检索命令"></a>find检索命令</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"># 在目录下找后缀是.mysql的文件</span><br><span class="line">find /home/eagleye -name &#x27;*.mysql&#x27; -print</span><br><span class="line"></span><br><span class="line"># 会从 /usr 目录开始往下找，找最近3天之内存取过的文件。</span><br><span class="line">find /usr -atime 3 –print</span><br><span class="line">  </span><br><span class="line"># 会从 /usr 目录开始往下找，找最近5天之内修改过的文件。</span><br><span class="line">find /usr -ctime 5 –print</span><br><span class="line"></span><br><span class="line"># 会从 /doc 目录开始往下找，找jacky 的、文件名开头是 j的文件。  </span><br><span class="line">find /doc -user jacky -name &#x27;j*&#x27; –print</span><br><span class="line"></span><br><span class="line"># 会从 /doc 目录开始往下找，找寻文件名是 ja 开头或者 ma开头的文件。</span><br><span class="line">find /doc \( -name &#x27;ja*&#x27; -o- -name &#x27;ma*&#x27; \) –print</span><br><span class="line"></span><br><span class="line">#  会从 /doc 目录开始往下找，找到凡是文件名结尾为 bak的文件，把它删除掉。-exec 选项是执行的意思，rm 是删除命令，&#123; &#125; 表示文件名，“\;”是规定的命令结尾。 </span><br><span class="line">find /doc -name &#x27;*bak&#x27; -exec rm &#123;&#125; \;</span><br></pre></td></tr></table></figure>

<hr>
<h1 id="网络相关"><a href="#网络相关" class="headerlink" title="网络相关"></a>网络相关</h1><h2 id="查看什么进程使用了该端口"><a href="#查看什么进程使用了该端口" class="headerlink" title="查看什么进程使用了该端口"></a>查看什么进程使用了该端口</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">lsof -i:port</span><br></pre></td></tr></table></figure>

<h2 id="获取本机ip地址"><a href="#获取本机ip地址" class="headerlink" title="获取本机ip地址"></a>获取本机ip地址</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk &#x27;&#123;print $2&#125;&#x27;|tr -d &quot;addr:&quot;</span><br></pre></td></tr></table></figure>

<h2 id="iptables"><a href="#iptables" class="headerlink" title="iptables"></a>iptables</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"># 查看iptables状态</span><br><span class="line">service iptables status</span><br><span class="line"></span><br><span class="line"># 要封停一个ip</span><br><span class="line">iptables -I INPUT -s ***.***.***.*** -j DROP</span><br><span class="line"></span><br><span class="line"># 要解封一个IP，使用下面这条命令：</span><br><span class="line">iptables -D INPUT -s ***.***.***.*** -j DROP</span><br><span class="line"></span><br><span class="line">备注: 参数-I是表示Insert（添加），-D表示Delete（删除）。后面跟的是规则，INPUT表示入站，***.***.***.***表示要封停的IP，DROP表示放弃连接。</span><br><span class="line"></span><br><span class="line">#开启9090端口的访问</span><br><span class="line">/sbin/iptables -I INPUT -p tcp --dport 9090 -j ACCEPT </span><br><span class="line"></span><br><span class="line"># 防火墙开启、关闭、重启</span><br><span class="line">/etc/init.d/iptables status</span><br><span class="line">/etc/init.d/iptables start</span><br><span class="line">/etc/init.d/iptables stop</span><br><span class="line">/etc/init.d/iptables restart</span><br></pre></td></tr></table></figure>

<h2 id="nc命令-tcp调试利器"><a href="#nc命令-tcp调试利器" class="headerlink" title="nc命令, tcp调试利器"></a>nc命令, tcp调试利器</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">#给某一个endpoint发送TCP请求,就将data的内容发送到对端</span><br><span class="line">nc 192.168.0.11 8000 &lt; data.txt</span><br><span class="line"></span><br><span class="line">#nc可以当做服务器，监听某个端口号,把某一次请求的内容存储到received_data里</span><br><span class="line">nc -l 8000 &gt; received_data</span><br><span class="line"></span><br><span class="line">#上边只监听一次，如果多次可以加上-k参数</span><br><span class="line">nc -lk 8000</span><br></pre></td></tr></table></figure>

<h2 id="tcpdump"><a href="#tcpdump" class="headerlink" title="tcpdump"></a>tcpdump</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># dump出本机12301端口的tcp包</span><br><span class="line">tcpdump -i em1 tcp port 12301 -s 1500 -w abc.pcap</span><br></pre></td></tr></table></figure>

<h2 id="跟踪网络路由路径"><a href="#跟踪网络路由路径" class="headerlink" title="跟踪网络路由路径"></a>跟踪网络路由路径</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"># traceroute默认使用udp方式, 如果是-I则改成icmp方式</span><br><span class="line">traceroute -I www.163.com</span><br><span class="line"></span><br><span class="line"># 从ttl第3跳跟踪</span><br><span class="line">traceroute -M 3 www.163.com  </span><br><span class="line"></span><br><span class="line"># 加上端口跟踪</span><br><span class="line">traceroute -p 8080 192.168.10.11</span><br></pre></td></tr></table></figure>

<h2 id="ss"><a href="#ss" class="headerlink" title="ss"></a>ss</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"># 显示本地打开的所有端口</span><br><span class="line">ss -l </span><br><span class="line"> </span><br><span class="line"># 显示每个进程具体打开的socket</span><br><span class="line">ss -pl </span><br><span class="line"> </span><br><span class="line"># 显示所有tcp socket</span><br><span class="line">ss -t -a </span><br><span class="line"> </span><br><span class="line"># 显示所有的UDP Socekt</span><br><span class="line">ss -u -a </span><br><span class="line"> </span><br><span class="line"># 显示所有已建立的SMTP连接</span><br><span class="line">ss -o state established &#x27;( dport = :smtp or sport = :smtp )&#x27;  </span><br><span class="line"> </span><br><span class="line"># 显示所有已建立的HTTP连接 </span><br><span class="line">ss -o state established &#x27;( dport = :http or sport = :http )&#x27;  </span><br><span class="line"> </span><br><span class="line">找出所有连接X服务器的进程</span><br><span class="line">ss -x src /tmp/.X11-unix/*  </span><br><span class="line"> </span><br><span class="line">列出当前socket统计信息</span><br><span class="line">ss -s </span><br><span class="line"> </span><br><span class="line">解释：netstat是遍历/proc下面每个PID目录，ss直接读/proc/net下面的统计信息。所以ss执行的时候消耗资源以及消耗的时间都比netstat少很多</span><br></pre></td></tr></table></figure>

<h2 id="netstat"><a href="#netstat" class="headerlink" title="netstat"></a>netstat</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"># 输出每个ip的连接数，以及总的各个状态的连接数</span><br><span class="line">netstat -n | awk &#x27;/^tcp/ &#123;n=split($(NF-1),array,&quot;:&quot;);if(n&lt;=2)++S[array[(1)]];else++S[array[(4)]];++s[$NF];++N&#125; END &#123;for(a in S)&#123;printf(&quot;%-20s %s\n&quot;, a, S[a]);++I&#125;printf(&quot;%-20s %s\n&quot;,&quot;TOTAL_IP&quot;,I);for(a in s) printf(&quot;%-20s %s\n&quot;,a, s[a]);printf(&quot;%-20s %s\n&quot;,&quot;TOTAL_LINK&quot;,N);&#125;&#x27;</span><br><span class="line"></span><br><span class="line"># 统计所有连接状态, </span><br><span class="line"># CLOSED：无连接是活动的或正在进行</span><br><span class="line"># LISTEN：服务器在等待进入呼叫</span><br><span class="line"># SYN_RECV：一个连接请求已经到达，等待确认</span><br><span class="line"># SYN_SENT：应用已经开始，打开一个连接</span><br><span class="line"># ESTABLISHED：正常数据传输状态</span><br><span class="line"># FIN_WAIT1：应用说它已经完成</span><br><span class="line"># FIN_WAIT2：另一边已同意释放</span><br><span class="line"># ITMED_WAIT：等待所有分组死掉</span><br><span class="line"># CLOSING：两边同时尝试关闭</span><br><span class="line"># TIME_WAIT：主动关闭连接一端还没有等到另一端反馈期间的状态</span><br><span class="line"># LAST_ACK：等待所有分组死掉</span><br><span class="line">netstat -n | awk &#x27;/^tcp/ &#123;++state[$NF]&#125; END &#123;for(key in state) print key,&quot;\t&quot;,state[key]&#125;&#x27;</span><br><span class="line"></span><br><span class="line"># 查找较多time_wait连接</span><br><span class="line">netstat -n|grep TIME_WAIT|awk &#x27;&#123;print $5&#125;&#x27;|sort|uniq -c|sort -rn|head -n20</span><br></pre></td></tr></table></figure>

<h1 id="监控linux性能命令"><a href="#监控linux性能命令" class="headerlink" title="监控linux性能命令"></a>监控linux性能命令</h1><h2 id="top"><a href="#top" class="headerlink" title="top"></a>top</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">按大写的 F 或 O 键，然后按 a-z 可以将进程按照相应的列进行排序, 然后回车。而大写的 R 键可以将当前的排序倒转</span><br></pre></td></tr></table></figure>

<table>
<thead>
<tr>
<th align="left">列名</th>
<th align="left">含义</th>
</tr>
</thead>
<tbody><tr>
<td align="left">PID</td>
<td align="left">进程id</td>
</tr>
<tr>
<td align="left">PPID</td>
<td align="left">父进程id</td>
</tr>
<tr>
<td align="left">RUSER</td>
<td align="left">Real user name</td>
</tr>
<tr>
<td align="left">UID</td>
<td align="left">进程所有者的用户id</td>
</tr>
<tr>
<td align="left">USER</td>
<td align="left">进程所有者的用户名</td>
</tr>
<tr>
<td align="left">GROUP</td>
<td align="left">进程所有者的组名</td>
</tr>
<tr>
<td align="left">TTY</td>
<td align="left">启动进程的终端名。不是从终端启动的进程则显示为 ?</td>
</tr>
<tr>
<td align="left">PR</td>
<td align="left">优先级</td>
</tr>
<tr>
<td align="left">NI</td>
<td align="left">nice值。负值表示高优先级，正值表示低优先级</td>
</tr>
<tr>
<td align="left">P</td>
<td align="left">最后使用的CPU，仅在多CPU环境下有意义</td>
</tr>
<tr>
<td align="left">%CPU</td>
<td align="left">上次更新到现在的CPU时间占用百分比</td>
</tr>
<tr>
<td align="left">TIME</td>
<td align="left">进程使用的CPU时间总计，单位秒</td>
</tr>
<tr>
<td align="left">TIME+</td>
<td align="left">进程使用的CPU时间总计，单位1&#x2F;100秒</td>
</tr>
<tr>
<td align="left">%MEM</td>
<td align="left">进程使用的物理内存百分比</td>
</tr>
<tr>
<td align="left">VIRT</td>
<td align="left">进程使用的虚拟内存总量，单位kb。VIRT&#x3D;SWAP+RES</td>
</tr>
<tr>
<td align="left">SWAP</td>
<td align="left">进程使用的虚拟内存中，被换出的大小，单位kb。</td>
</tr>
<tr>
<td align="left">RES</td>
<td align="left">进程使用的、未被换出的物理内存大小，单位kb。RES&#x3D;CODE+DATA</td>
</tr>
<tr>
<td align="left">CODE</td>
<td align="left">可执行代码占用的物理内存大小，单位kb</td>
</tr>
<tr>
<td align="left">DATA</td>
<td align="left">可执行代码以外的部分(数据段+栈)占用的物理内存大小，单位kb</td>
</tr>
<tr>
<td align="left">SHR</td>
<td align="left">共享内存大小，单位kb</td>
</tr>
<tr>
<td align="left">nFLT</td>
<td align="left">页面错误次数</td>
</tr>
<tr>
<td align="left">nDRT</td>
<td align="left">最后一次写入到现在，被修改过的页面数。</td>
</tr>
<tr>
<td align="left">S</td>
<td align="left">进程状态。D&#x3D;不可中断的睡眠状态,R&#x3D;运行,S&#x3D;睡眠,T&#x3D;跟踪&#x2F;停止,Z&#x3D;僵尸进程</td>
</tr>
<tr>
<td align="left">COMMAND</td>
<td align="left">命令名&#x2F;命令行</td>
</tr>
<tr>
<td align="left">WCHAN</td>
<td align="left">若该进程在睡眠，则显示睡眠中的系统函数名</td>
</tr>
<tr>
<td align="left">Flags</td>
<td align="left">任务标志，参考 sched.h</td>
</tr>
</tbody></table>
<h2 id="dmesg-查看系统日志"><a href="#dmesg-查看系统日志" class="headerlink" title="dmesg,查看系统日志"></a>dmesg,查看系统日志</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dmesg</span><br></pre></td></tr></table></figure>

<h2 id="iostat-磁盘IO情况监控"><a href="#iostat-磁盘IO情况监控" class="headerlink" title="iostat,磁盘IO情况监控"></a>iostat,磁盘IO情况监控</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">iostat -xz 1</span><br><span class="line"> </span><br><span class="line"># r/s, w/s, rkB/s, wkB/s：分别表示每秒读写次数和每秒读写数据量（千字节）。读写量过大，可能会引起性能问题。</span><br><span class="line"># await：IO操作的平均等待时间，单位是毫秒。这是应用程序在和磁盘交互时，需要消耗的时间，包括IO等待和实际操作的耗时。如果这个数值过大，可能是硬件设备遇到了瓶颈或者出现故障。</span><br><span class="line"># avgqu-sz：向设备发出的请求平均数量。如果这个数值大于1，可能是硬件设备已经饱和（部分前端硬件设备支持并行写入）。</span><br><span class="line"># %util：设备利用率。这个数值表示设备的繁忙程度，经验值是如果超过60，可能会影响IO性能（可以参照IO操作平均等待时间）。如果到达100%，说明硬件设备已经饱和。</span><br><span class="line"># 如果显示的是逻辑设备的数据，那么设备利用率不代表后端实际的硬件设备已经饱和。值得注意的是，即使IO性能不理想，也不一定意味这应用程序性能会不好，可以利用诸如预读取、写缓存等策略提升应用性能。</span><br></pre></td></tr></table></figure>

<h2 id="free-内存使用情况"><a href="#free-内存使用情况" class="headerlink" title="free,内存使用情况"></a>free,内存使用情况</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">free -m</span><br><span class="line"> </span><br><span class="line">eg:</span><br><span class="line"> </span><br><span class="line">     total       used       free     shared    buffers     cached</span><br><span class="line">Mem:          1002        769        232          0         62        421</span><br><span class="line">-/+ buffers/cache:          286        715</span><br><span class="line">Swap:          1153          0       1153</span><br><span class="line"> </span><br><span class="line">第一部分Mem行:</span><br><span class="line">total 内存总数: 1002M</span><br><span class="line">used 已经使用的内存数: 769M</span><br><span class="line">free 空闲的内存数: 232M</span><br><span class="line">shared 当前已经废弃不用,总是0</span><br><span class="line">buffers Buffer 缓存内存数: 62M</span><br><span class="line">cached Page 缓存内存数:421M</span><br><span class="line"> </span><br><span class="line">关系：total(1002M) = used(769M) + free(232M)</span><br><span class="line"> </span><br><span class="line">第二部分(-/+ buffers/cache):</span><br><span class="line">(-buffers/cache) used内存数：286M (指的第一部分Mem行中的used – buffers – cached)</span><br><span class="line">(+buffers/cache) free内存数: 715M (指的第一部分Mem行中的free + buffers + cached)</span><br><span class="line"> </span><br><span class="line">可见-buffers/cache反映的是被程序实实在在吃掉的内存,而+buffers/cache反映的是可以挪用的内存总数.</span><br><span class="line"> </span><br><span class="line">第三部分是指交换分区</span><br></pre></td></tr></table></figure>

<h2 id="sar-查看网络吞吐状态"><a href="#sar-查看网络吞吐状态" class="headerlink" title="sar,查看网络吞吐状态"></a>sar,查看网络吞吐状态</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"># sar命令在这里可以查看网络设备的吞吐率。在排查性能问题时，可以通过网络设备的吞吐量，判断网络设备是否已经饱和</span><br><span class="line">sar -n DEV 1</span><br><span class="line"> </span><br><span class="line">#</span><br><span class="line"># sar命令在这里用于查看TCP连接状态，其中包括：</span><br><span class="line"># active/s：每秒本地发起的TCP连接数，既通过connect调用创建的TCP连接；</span><br><span class="line"># passive/s：每秒远程发起的TCP连接数，即通过accept调用创建的TCP连接；</span><br><span class="line"># retrans/s：每秒TCP重传数量；</span><br><span class="line"># TCP连接数可以用来判断性能问题是否由于建立了过多的连接，进一步可以判断是主动发起的连接，还是被动接受的连接。TCP重传可能是因为网络环境恶劣，或者服务器压力过大导致丢包</span><br><span class="line">sar -n TCP,ETCP 1</span><br></pre></td></tr></table></figure>

<h2 id="vmstat-给定时间监控CPU使用率-内存使用-虚拟内存交互-IO读写"><a href="#vmstat-给定时间监控CPU使用率-内存使用-虚拟内存交互-IO读写" class="headerlink" title="vmstat, 给定时间监控CPU使用率, 内存使用, 虚拟内存交互, IO读写"></a>vmstat, 给定时间监控CPU使用率, 内存使用, 虚拟内存交互, IO读写</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"># 2表示每2秒采集一次状态信息, 1表示只采集一次(忽略既是一直采集)</span><br><span class="line">vmstat 2 1</span><br><span class="line"> </span><br><span class="line">eg:</span><br><span class="line">r b swpd free buff cache si so bi bo in cs us sy id wa</span><br><span class="line">1 0 0 3499840 315836 3819660 0 0 0 1 2 0 0 0 100 0</span><br><span class="line">0 0 0 3499584 315836 3819660 0 0 0 0 88 158 0 0 100 0</span><br><span class="line">0 0 0 3499708 315836 3819660 0 0 0 2 86 162 0 0 100 0</span><br><span class="line">0 0 0 3499708 315836 3819660 0 0 0 10 81 151 0 0 100 0</span><br><span class="line">1 0 0 3499732 315836 3819660 0 0 0 2 83 154 0 0 100 0</span><br></pre></td></tr></table></figure>

<ul>
<li><strong>r</strong> 表示运行队列(就是说多少个进程真的分配到CPU)，我测试的服务器目前CPU比较空闲，没什么程序在跑，当这个值超过了CPU数目，就会出现CPU瓶颈了。这个也和top的负载有关系，一般负载超过了3就比较高，超过了5就高，超过了10就不正常了，服务器的状态很危险。top的负载类似每秒的运行队列。如果运行队列过大，表示你的CPU很繁忙，一般会造成CPU使用率很高。</li>
<li><strong>b</strong> 表示阻塞的进程,这个不多说，进程阻塞，大家懂的。</li>
<li><strong>swpd</strong> 虚拟内存已使用的大小，如果大于0，表示你的机器物理内存不足了，如果不是程序内存泄露的原因，那么你该升级内存了或者把耗内存的任务迁移到其他机器。</li>
<li><strong>free</strong> 空闲的物理内存的大小，我的机器内存总共8G，剩余3415M。</li>
<li><strong>buff</strong> Linux&#x2F;Unix系统是用来存储，目录里面有什么内容，权限等的缓存，我本机大概占用300多M</li>
<li><strong>cache</strong> cache直接用来记忆我们打开的文件,给文件做缓冲，我本机大概占用300多M(这里是Linux&#x2F;Unix的聪明之处，把空闲的物理内存的一部分拿来做文件和目录的缓存，是为了提高 程序执行的性能，当程序使用内存时，buffer&#x2F;cached会很快地被使用。)</li>
<li><strong>si</strong> 每秒从磁盘读入虚拟内存的大小，如果这个值大于0，表示物理内存不够用或者内存泄露了，要查找耗内存进程解决掉。我的机器内存充裕，一切正常。</li>
<li><strong>so</strong> 每秒虚拟内存写入磁盘的大小，如果这个值大于0，同上。</li>
<li><strong>bi</strong> 块设备每秒接收的块数量，这里的块设备是指系统上所有的磁盘和其他块设备，默认块大小是1024byte，我本机上没什么IO操作，所以一直是0，但是我曾在处理拷贝大量数据(2-3T)的机器上看过可以达到140000&#x2F;s，磁盘写入速度差不多140M每秒</li>
<li><strong>bo</strong> 块设备每秒发送的块数量，例如我们读取文件，bo就要大于0。bi和bo一般都要接近0，不然就是IO过于频繁，需要调整。</li>
<li><strong>in</strong> 每秒CPU的中断次数，包括时间中断</li>
<li><strong>cs</strong> 每秒上下文切换次数，例如我们调用系统函数，就要进行上下文切换，线程的切换，也要进程上下文切换，这个值要越小越好，太大了，要考虑调低线程或者进程的数目,例如在apache和nginx这种web服务器中，我们一般做性能测试时会进行几千并发甚至几万并发的测试，选择web服务器的进程可以由进程或者线程的峰值一直下调，压测，直到cs到一个比较小的值，这个进程和线程数就是比较合适的值了。系统调用也是，每次调用系统函数，我们的代码就会进入内核空间，导致上下文切换，这个是很耗资源，也要尽量避免频繁调用系统函数。上下文切换次数过多表示你的CPU大部分浪费在上下文切换，导致CPU干正经事的时间少了，CPU没有充分利用，是不可取的。</li>
<li><strong>us</strong> 用户CPU时间，我曾经在一个做加密解密很频繁的服务器上，可以看到us接近100,r运行队列达到80(机器在做压力测试，性能表现不佳)。</li>
<li><strong>sy</strong> 系统CPU时间，如果太高，表示系统调用时间长，例如是IO操作频繁。</li>
<li><strong>id</strong> 空闲 CPU时间，一般来说，id + us + sy &#x3D; 100,一般我认为id是空闲CPU使用率，us是用户CPU使用率，sy是系统CPU使用率。</li>
<li><strong>wt</strong> 等待IO CPU时间。</li>
</ul>

      
    </div>
    <footer class="article-footer">
      
        <div id="donation_div"></div>


<script src="/qingfeng-blog/js/vdonate.js"></script>

<script>
var a = new Donate({
  title: '如果觉得我的文章对您有用，请随意打赏。您的支持将鼓励我继续创作!', // 可选参数，打赏标题
  btnText: 'Donate', // 可选参数，打赏按钮文字
  el: document.getElementById('donation_div'),
  wechatImage: 'http://img.lindaifeng.vip/typora-picgo-tuchaung/20230428150832.png',
  alipayImage: 'http://img.lindaifeng.vip/typora-picgo-tuchaung/20230428150823.png'
});
</script>
      
      
      <div>
        <ul class="post-copyright">
          <li class="post-copyright-author">
          <strong>Post author:  </strong>清峰</a>
          </li>
          <li class="post-copyright-link">
          <strong>Post link:  </strong>
          <a href="/qingfeng-blog/2021/11/30/Linux/Java 开发常用的 Linux 命令/" target="_blank" title="Java 开发常用的 Linux 命令">http://example.com/2021/11/30/Linux/Java 开发常用的 Linux 命令/</a>
          </li>
          <li class="post-copyright-license">
            <strong>Copyright Notice:   </strong>
            All articles in this blog are licensed under <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">CC BY-NC-ND 4.0</a>
            unless stating additionally.
          </li>
         
        </ul>
<div>

      
      
        
	<div id="comment">
		<!-- 来必力City版安装代码 -->
		<div id="lv-container" data-id="city" data-uid="MTAyMC8yOTQ4MS82MDQ5">
		<script type="text/javascript">
		   (function(d, s) {
		       var j, e = d.getElementsByTagName(s)[0];

		       if (typeof LivereTower === 'function') { return; }

		       j = d.createElement(s);
		       j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
		       j.async = true;

		       e.parentNode.insertBefore(j, e);
		   })(document, 'script');
		</script>
		<noscript>为正常使用来必力评论功能请激活JavaScript</noscript>
		</div>
		<!-- City版安装代码已完成 -->
	</div>



      
      
        
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/qingfeng-blog/tags/java/" rel="tag">java</a></li></ul>

      

    </footer>
  </div>
</div>
  
    
<nav id="article-nav">
  
    <a href="/qingfeng-blog/2022/01/27/Docker/Docker%E4%BB%8B%E7%BB%8D/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Docker介绍
        
      </div>
    </a>
  
  
    <a href="/qingfeng-blog/2021/09/14/%E8%BF%90%E7%BB%B4%E5%AE%89%E8%A3%85/Linux%E5%AE%89%E8%A3%85mongo%E4%B8%BB%E4%BB%8E%E6%A8%A1%E5%BC%8F/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Linux安装mongo主从模式</div>
    </a>
  
</nav>

  
</article>

<!-- Table of Contents -->

  <aside id="toc-sidebar">
    <div id="toc" class="toc-article">
    <strong class="toc-title">Contents</strong>
    
        <ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Java-%E5%BC%80%E5%8F%91%E5%B8%B8%E7%94%A8%E7%9A%84-Linux-%E5%91%BD%E4%BB%A4%E7%9F%A5%E8%AF%86%E7%A7%AF%E7%B4%AF"><span class="nav-number">1.</span> <span class="nav-text">Java 开发常用的 Linux 命令知识积累</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C"><span class="nav-number">1.1.</span> <span class="nav-text">基本操作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Linux%E5%85%B3%E6%9C%BA-%E9%87%8D%E5%90%AF"><span class="nav-number">1.2.</span> <span class="nav-text">Linux关机,重启</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E7%B3%BB%E7%BB%9F-CPU%E4%BF%A1%E6%81%AF"><span class="nav-number">1.3.</span> <span class="nav-text">查看系统,CPU信息</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%BB%BA%E7%AB%8B%E8%BD%AF%E8%BF%9E%E6%8E%A5"><span class="nav-number">1.4.</span> <span class="nav-text">建立软连接</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#rpm%E7%9B%B8%E5%85%B3"><span class="nav-number">1.5.</span> <span class="nav-text">rpm相关</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#sshkey"><span class="nav-number">1.6.</span> <span class="nav-text">sshkey</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%91%BD%E4%BB%A4%E9%87%8D%E5%91%BD%E5%90%8D"><span class="nav-number">1.7.</span> <span class="nav-text">命令重命名</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%90%8C%E6%AD%A5%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%97%B6%E9%97%B4"><span class="nav-number">1.8.</span> <span class="nav-text">同步服务器时间</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%90%8E%E5%8F%B0%E8%BF%90%E8%A1%8C%E5%91%BD%E4%BB%A4"><span class="nav-number">1.9.</span> <span class="nav-text">后台运行命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%BC%BA%E5%88%B6%E6%B4%BB%E5%8A%A8%E7%94%A8%E6%88%B7%E9%80%80%E5%87%BA"><span class="nav-number">1.10.</span> <span class="nav-text">强制活动用户退出</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E5%91%BD%E4%BB%A4%E8%B7%AF%E5%BE%84"><span class="nav-number">1.11.</span> <span class="nav-text">查看命令路径</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E8%BF%9B%E7%A8%8B%E6%89%80%E6%9C%89%E6%89%93%E5%BC%80%E6%9C%80%E5%A4%A7fd%E6%95%B0"><span class="nav-number">1.12.</span> <span class="nav-text">查看进程所有打开最大fd数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%85%8D%E7%BD%AEdns"><span class="nav-number">1.13.</span> <span class="nav-text">配置dns</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#nslookup-%E6%9F%A5%E7%9C%8B%E5%9F%9F%E5%90%8D%E8%B7%AF%E7%94%B1%E8%A1%A8"><span class="nav-number">1.14.</span> <span class="nav-text">nslookup,查看域名路由表</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#last-%E6%9C%80%E8%BF%91%E7%99%BB%E5%BD%95%E4%BF%A1%E6%81%AF%E5%88%97%E8%A1%A8"><span class="nav-number">1.15.</span> <span class="nav-text">last, 最近登录信息列表</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%AE%BE%E7%BD%AE%E5%9B%BA%E5%AE%9Aip"><span class="nav-number">1.16.</span> <span class="nav-text">设置固定ip</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E8%BF%9B%E7%A8%8B%E5%86%85%E5%8A%A0%E8%BD%BD%E7%9A%84%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F"><span class="nav-number">1.17.</span> <span class="nav-text">查看进程内加载的环境变量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E8%BF%9B%E7%A8%8B%E6%A0%91%E6%89%BE%E5%88%B0%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%BF%9B%E7%A8%8B"><span class="nav-number">1.18.</span> <span class="nav-text">查看进程树找到服务器进程</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E8%BF%9B%E7%A8%8B%E5%90%AF%E5%8A%A8%E8%B7%AF%E5%BE%84"><span class="nav-number">1.19.</span> <span class="nav-text">查看进程启动路径</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B7%BB%E5%8A%A0%E7%94%A8%E6%88%B7-%E9%85%8D%E7%BD%AEsudo%E6%9D%83%E9%99%90"><span class="nav-number">1.20.</span> <span class="nav-text">添加用户, 配置sudo权限</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%BC%BA%E5%88%B6%E5%85%B3%E9%97%AD%E8%BF%9B%E7%A8%8B%E5%90%8D%E5%8C%85%E5%90%ABxxx%E7%9A%84%E6%89%80%E6%9C%89%E8%BF%9B%E7%A8%8B"><span class="nav-number">1.21.</span> <span class="nav-text">强制关闭进程名包含xxx的所有进程</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%A3%81%E7%9B%98-%E6%96%87%E4%BB%B6-%E7%9B%AE%E5%BD%95%E7%9B%B8%E5%85%B3%E6%93%8D%E4%BD%9C"><span class="nav-number">2.</span> <span class="nav-text">磁盘,文件,目录相关操作</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#vim%E6%93%8D%E4%BD%9C"><span class="nav-number">2.1.</span> <span class="nav-text">vim操作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%89%93%E5%BC%80%E5%8F%AA%E8%AF%BB%E6%96%87%E4%BB%B6-%E4%BF%AE%E6%94%B9%E5%90%8E%E9%9C%80%E8%A6%81%E4%BF%9D%E5%AD%98%E6%97%B6-%E4%B8%8D%E7%94%A8%E5%88%87%E6%8D%A2%E7%94%A8%E6%88%B7%E5%8D%B3%E5%8F%AF%E4%BF%9D%E5%AD%98%E7%9A%84%E6%96%B9%E5%BC%8F"><span class="nav-number">2.2.</span> <span class="nav-text">打开只读文件,修改后需要保存时(不用切换用户即可保存的方式)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E7%A3%81%E7%9B%98-%E6%96%87%E4%BB%B6%E7%9B%AE%E5%BD%95%E5%9F%BA%E6%9C%AC%E4%BF%A1%E6%81%AF"><span class="nav-number">2.3.</span> <span class="nav-text">查看磁盘, 文件目录基本信息</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#wc%E5%91%BD%E4%BB%A4"><span class="nav-number">2.4.</span> <span class="nav-text">wc命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B8%B8%E7%94%A8%E5%8E%8B%E7%BC%A9-%E8%A7%A3%E5%8E%8B%E7%BC%A9%E5%91%BD%E4%BB%A4"><span class="nav-number">2.5.</span> <span class="nav-text">常用压缩, 解压缩命令</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%8E%8B%E7%BC%A9%E5%91%BD%E4%BB%A4"><span class="nav-number">2.5.1.</span> <span class="nav-text">压缩命令</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%A7%A3%E5%8E%8B%E7%BC%A9%E5%91%BD%E4%BB%A4"><span class="nav-number">2.5.2.</span> <span class="nav-text">解压缩命令</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8F%98%E6%9B%B4%E6%96%87%E4%BB%B6%E6%89%80%E5%B1%9E%E7%94%A8%E6%88%B7-%E7%94%A8%E6%88%B7%E7%BB%84"><span class="nav-number">2.6.</span> <span class="nav-text">变更文件所属用户, 用户组</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#cp-scp-mkdir"><span class="nav-number">2.7.</span> <span class="nav-text">cp, scp, mkdir</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%AF%94%E8%BE%83%E4%B8%A4%E4%B8%AA%E6%96%87%E4%BB%B6"><span class="nav-number">2.8.</span> <span class="nav-text">比较两个文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%97%A5%E5%BF%97%E8%BE%93%E5%87%BA%E7%9A%84%E5%AD%97%E8%8A%82%E6%95%B0-%E5%8F%AF%E4%BB%A5%E7%94%A8%E4%BD%9C%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95"><span class="nav-number">2.9.</span> <span class="nav-text">日志输出的字节数,可以用作性能测试</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B-%E5%8E%BB%E9%99%A4%E7%89%B9%E6%AE%8A%E5%AD%97%E7%AC%A6"><span class="nav-number">2.10.</span> <span class="nav-text">查看, 去除特殊字符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%A4%84%E7%90%86%E5%9B%A0%E7%B3%BB%E7%BB%9F%E5%8E%9F%E5%9B%A0%E5%BC%95%E8%B5%B7%E7%9A%84%E6%96%87%E4%BB%B6%E4%B8%AD%E7%89%B9%E6%AE%8A%E5%AD%97%E7%AC%A6%E7%9A%84%E9%97%AE%E9%A2%98"><span class="nav-number">2.11.</span> <span class="nav-text">处理因系统原因引起的文件中特殊字符的问题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#tee-%E9%87%8D%E5%AE%9A%E5%90%91%E7%9A%84%E5%90%8C%E6%97%B6%E8%BE%93%E5%87%BA%E5%88%B0%E5%B1%8F%E5%B9%95"><span class="nav-number">2.12.</span> <span class="nav-text">tee, 重定向的同时输出到屏幕</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%A3%80%E7%B4%A2%E7%9B%B8%E5%85%B3"><span class="nav-number">3.</span> <span class="nav-text">检索相关</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#grep"><span class="nav-number">3.1.</span> <span class="nav-text">grep</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#awk"><span class="nav-number">3.2.</span> <span class="nav-text">awk</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#find%E6%A3%80%E7%B4%A2%E5%91%BD%E4%BB%A4"><span class="nav-number">3.3.</span> <span class="nav-text">find检索命令</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%BD%91%E7%BB%9C%E7%9B%B8%E5%85%B3"><span class="nav-number">4.</span> <span class="nav-text">网络相关</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E4%BB%80%E4%B9%88%E8%BF%9B%E7%A8%8B%E4%BD%BF%E7%94%A8%E4%BA%86%E8%AF%A5%E7%AB%AF%E5%8F%A3"><span class="nav-number">4.1.</span> <span class="nav-text">查看什么进程使用了该端口</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%8E%B7%E5%8F%96%E6%9C%AC%E6%9C%BAip%E5%9C%B0%E5%9D%80"><span class="nav-number">4.2.</span> <span class="nav-text">获取本机ip地址</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#iptables"><span class="nav-number">4.3.</span> <span class="nav-text">iptables</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#nc%E5%91%BD%E4%BB%A4-tcp%E8%B0%83%E8%AF%95%E5%88%A9%E5%99%A8"><span class="nav-number">4.4.</span> <span class="nav-text">nc命令, tcp调试利器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#tcpdump"><span class="nav-number">4.5.</span> <span class="nav-text">tcpdump</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%B7%9F%E8%B8%AA%E7%BD%91%E7%BB%9C%E8%B7%AF%E7%94%B1%E8%B7%AF%E5%BE%84"><span class="nav-number">4.6.</span> <span class="nav-text">跟踪网络路由路径</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ss"><span class="nav-number">4.7.</span> <span class="nav-text">ss</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#netstat"><span class="nav-number">4.8.</span> <span class="nav-text">netstat</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%9B%91%E6%8E%A7linux%E6%80%A7%E8%83%BD%E5%91%BD%E4%BB%A4"><span class="nav-number">5.</span> <span class="nav-text">监控linux性能命令</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#top"><span class="nav-number">5.1.</span> <span class="nav-text">top</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#dmesg-%E6%9F%A5%E7%9C%8B%E7%B3%BB%E7%BB%9F%E6%97%A5%E5%BF%97"><span class="nav-number">5.2.</span> <span class="nav-text">dmesg,查看系统日志</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#iostat-%E7%A3%81%E7%9B%98IO%E6%83%85%E5%86%B5%E7%9B%91%E6%8E%A7"><span class="nav-number">5.3.</span> <span class="nav-text">iostat,磁盘IO情况监控</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#free-%E5%86%85%E5%AD%98%E4%BD%BF%E7%94%A8%E6%83%85%E5%86%B5"><span class="nav-number">5.4.</span> <span class="nav-text">free,内存使用情况</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#sar-%E6%9F%A5%E7%9C%8B%E7%BD%91%E7%BB%9C%E5%90%9E%E5%90%90%E7%8A%B6%E6%80%81"><span class="nav-number">5.5.</span> <span class="nav-text">sar,查看网络吞吐状态</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#vmstat-%E7%BB%99%E5%AE%9A%E6%97%B6%E9%97%B4%E7%9B%91%E6%8E%A7CPU%E4%BD%BF%E7%94%A8%E7%8E%87-%E5%86%85%E5%AD%98%E4%BD%BF%E7%94%A8-%E8%99%9A%E6%8B%9F%E5%86%85%E5%AD%98%E4%BA%A4%E4%BA%92-IO%E8%AF%BB%E5%86%99"><span class="nav-number">5.6.</span> <span class="nav-text">vmstat, 给定时间监控CPU使用率, 内存使用, 虚拟内存交互, IO读写</span></a></li></ol></li></ol>
    
    </div>
  </aside>


</section>
        
      </div>
      
      <footer id="footer">
  

  <div class="container">
      	<div class="row">
	      <!-- <p> Powered by <a href="http://hexo.io/" target="_blank">Hexo</a> and <a href="https://github.com/iTimeTraveler/hexo-theme-hiker" target="_blank">Hexo-theme-hiker</a> </p> -->
	      <p>May there be no bug in the world！</p>
        <p id="copyRightEn">Copyright &copy; 2022 - 2023 All Rights Reserved.</p>
	      
	      
    		<p class="busuanzi_uv">
				UV : <span id="busuanzi_value_site_uv"></span> |  
				PV : <span id="busuanzi_value_site_pv"></span>
		    </p>
  		   
		</div>

		
  </div>
</footer>


<!-- min height -->

<script>
    var wrapdiv = document.getElementById("wrap");
    var contentdiv = document.getElementById("content");
    var allheader = document.getElementById("allheader");

    wrapdiv.style.minHeight = document.body.offsetHeight + "px";
    if (allheader != null) {
      contentdiv.style.minHeight = document.body.offsetHeight - allheader.offsetHeight - document.getElementById("footer").offsetHeight + "px";
    } else {
      contentdiv.style.minHeight = document.body.offsetHeight - document.getElementById("footer").offsetHeight + "px";
    }
</script>
    </div>
    <!-- <nav id="mobile-nav">
  
    <a href="/qingfeng-blog/" class="mobile-nav-link">首页</a>
  
    <a href="/qingfeng-blog/categories" class="mobile-nav-link">分类</a>
  
    <a href="/qingfeng-blog/tags" class="mobile-nav-link">标签</a>
  
</nav> -->
    

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  
<link rel="stylesheet" href="/qingfeng-blog/fancybox/jquery.fancybox.css">

  
<script src="/qingfeng-blog/fancybox/jquery.fancybox.pack.js"></script>




<script src="/qingfeng-blog/js/scripts.js"></script>



  
<script src="/qingfeng-blog/js/home.js"></script>




  
<script src="/qingfeng-blog/js/dialog.js"></script>









	<div style="display: none;">
    <script src="https://s95.cnzz.com/z_stat.php?id=1260716016&web_id=1260716016" language="JavaScript"></script>
  </div>



	<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js">
	</script>






  </div>

  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title" id="myModalLabel">设置</h2>
      </div>
      <hr style="margin-top:0px; margin-bottom:0px; width:80%; border-top: 3px solid #000;">
      <hr style="margin-top:2px; margin-bottom:0px; width:80%; border-top: 1px solid #000;">


      <div class="modal-body">
          <div style="margin:6px;">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" onclick="javascript:setFontSize();" aria-expanded="true" aria-controls="collapseOne">
              正文字号大小
            </a>
          </div>
          <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
          <div class="panel-body">
            您已调整页面字体大小
          </div>
        </div>
      


          <div style="margin:6px;">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" onclick="javascript:setBackground();" aria-expanded="true" aria-controls="collapseTwo">
              夜间护眼模式
            </a>
        </div>
          <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
          <div class="panel-body">
            夜间模式已经开启，再次单击按钮即可关闭 
          </div>
        </div>

        <div>
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="true" aria-controls="collapseThree">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;关 于&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
        </div>
         <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
          <div class="panel-body">
            清峰小栈
          </div>
          <div class="panel-body">
            Copyright © 2023 清峰 All Rights Reserved.
          </div>
        </div>
      </div>


      <hr style="margin-top:0px; margin-bottom:0px; width:80%; border-top: 1px solid #000;">
      <hr style="margin-top:2px; margin-bottom:0px; width:80%; border-top: 3px solid #000;">
      <div class="modal-footer">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
      </div>
    </div>
  </div>
</div>
  
  <a id="rocket" href="#top" class=""></a>
  <script type="text/javascript" src="/qingfeng-blog/js/totop.js?v=1.0.0" async=""></script>
  
    <a id="menu-switch"><i class="fa fa-bars fa-lg"></i></a>
  
</body>
</html>